var Q = require('q'),
    entityCollection = require('../../../Base/server/controllers/EntityCollection');

//查找所有的部门by部门名
exports.findAllDepartmentByName = function(name, completeFun) {
    var entity = entityCollection.getEntity("Department");
    
    entity.findOne({
        Name: name
    }, null, function(err, record) {
        if (err) {
            var newErr = new Error();
            newErr.leval = 9;
            newErr.title = '查询部门信息错误';
            newErr.message = '请检查查询参数！';
            completeFun(newErr);
        } else {
            completeFun(null, record);
        }
    });
};
//查找所有的部门byCode
exports.findAllDepartmentByCode = function(code, completeFun) {
    var entity = entityCollection.getEntity("Department");
    
    entity.findOne({
        Code: code
    }, null, function(err, record) {
        if (err) {
            var newErr = new Error();
            newErr.leval = 9;
            newErr.title = '查询部门信息错误';
            newErr.message = '请检查查询参数！';
            completeFun(newErr);
        } else {
            completeFun(null, record);
        }
    });
};


